import { defineConfig } from "vite";
import path from "path";
import vue from "@vitejs/plugin-vue";

export default defineConfig({
  plugins: [vue()],
  resolve: {
    // https://cn.vitejs.dev/config/#resolve-alias
    alias: {
      // 设置路径
      "~": path.resolve(__dirname, "./"),
      // 设置别名
      "@": path.resolve(__dirname, "./src"),
      "fast-deep-equal": "fast-deep-equal/es6",
    },

    // https://cn.vitejs.dev/config/#resolve-extensions
    extensions: [".mjs", ".js", ".ts", ".jsx", ".tsx", ".json", ".vue"],
  },
  server: {
    port: 5173,
    host: "0.0.0.0",
    proxy: {
      // 保留原有的 WebSocket 代理
      "/ws": {
        target: "http://localhost:8070",
        changeOrigin: true,
        ws: true, // 支持 WebSocket
      },
      // ✅ 新增：代理所有 /api 请求
      "/api": {
        target: "http://localhost:8070", // 后端地址
        changeOrigin: true, // 支持跨域
        rewrite: (path) => path, // 可选：重写路径（这里不需要改）
        // secure: false,                    // 如果后端是 HTTPS，才需要设为 true
      },
    },
  },
  define: {
    global: "globalThis",
  },
});
